package pokerTests;

import static org.junit.Assert.*;

import org.junit.Test;
import poker.*;

public class TableLogicTest {

	@Test
	public void payUp_normalData_expectCorrectResult() throws Exception {
		Player thePlayers[] = new Player[4];
		int players[] = new int[4];
		
		thePlayers[0] = new Human("Zdzisiek1", 400);
		thePlayers[0].setBet(55);
		thePlayers[0].fold();
		players[0] = -1;
		
		thePlayers[1] = new Human("Zdzisiek2", 20);
		thePlayers[1].setBet(20);
		thePlayers[1].allIn();
		players[1] = 1;
		
		thePlayers[2] = new Human("Zdzisiek3", 450);
		thePlayers[2].setBet(200);
		players[2] = 2;
		
		thePlayers[3] = new Human("Zdzisiek4", 200);
		thePlayers[3].setBet(105);
		thePlayers[3].allIn();
		players[3] = -1;
		
		Table.payUp(2, players, thePlayers);
		assertEquals(thePlayers[0].getTokens(), 353);  //400-(55/2 + 20)
		assertEquals(thePlayers[1].getTokens(), 60);
		assertEquals(thePlayers[2].getTokens(), 529);  //450+55/2+105/2
		assertEquals(thePlayers[3].getTokens(), 128);
	}
	
	@Test
	public void payUp_drawGame_expectNoChange() throws Exception {
		Player thePlayers[] = new Player[4];
		int players[] = new int[4];
		
		thePlayers[0] = new Human("Zdzisiek1", 400);
		thePlayers[0].setBet(33);
		players[0] = 0;
		
		thePlayers[1] = new Human("Zdzisiek2", 400);
		thePlayers[1].setBet(33);
		players[1] = 1;
		
		thePlayers[2] = new Human("Zdzisiek3", 400);
		thePlayers[2].setBet(33);
		players[2] = 2;
		
		thePlayers[3] = new Human("Zdzisiek4", 400);
		thePlayers[3].setBet(33);
		players[3] = 3;
		Table.payUp(4, players, thePlayers);
		assertEquals(thePlayers[0].getTokens(), 400);
		assertEquals(thePlayers[1].getTokens(), 400);
		assertEquals(thePlayers[2].getTokens(), 400);
		assertEquals(thePlayers[3].getTokens(), 400);
	}
}
